﻿
namespace SomethingSpacialClassLib.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.Server;
    using System.ServiceModel.DomainServices.EntityFramework;


    // Implements application logic using the SUGWTKEntities1 context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    public partial class SomethingSpacialService : LinqToEntitiesDomainService<SUGWTKEntities1>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Event> GetEvents()
        {
            return this.ObjectContext.Events;
        }

        public IQueryable<Event> GetEventLatest()
        {
            return this.ObjectContext.Events.OrderByDescending(e => e.EVT_Start_Date).Take(1);
        }

        public IQueryable<Event> GetEventsPrevious()
        {
            return this.ObjectContext.Events.OrderByDescending(e => e.EVT_Start_Date);
        }

        public void InsertEvent(Event @event)
        {

                if ((@event.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(@event, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.Events.AddObject(@event);
                }
        }

        public void UpdateEvent(Event currentEvent)
        {
            if ((currentEvent.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Events.AttachAsModified(currentEvent, this.ChangeSet.GetOriginal(currentEvent));
            }
        }

        public void DeleteEvent(Event @event)
        {
            if ((@event.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Events.Attach(@event);
            }
            this.ObjectContext.Events.DeleteObject(@event);
        }

    }
}


